<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/get-host-info.js"></script>
<script>
    test(function () {
        assert_true(window.isSecureContext);
    }, "Sanity-check the test runner.");

    async_test(t => {
        var w = new Worker("./resources/post-securecontext.js");
        w.onmessage = t.step_func_done(e => {
            assert_true(e.data.isSecureContext);
        });
    }, "Secure workers are secure.");

    async_test(t => {
        var url = URL.createObjectURL(new Blob(['postMessage({ "isSecureContext": self.isSecureContext });']));
        var w = new Worker(url);
        w.onmessage = t.step_func_done(e => {
            assert_true(e.data.isSecureContext);
        });
    }, "Secure workers created from 'blob:' are secure.");

    async_test(t => {
        var w = new SharedWorker("./resources/post-securecontext-shared.js");
        w.port.onmessage = t.step_func_done(e => {
            assert_true(e.data.isSecureContext);
        });
    }, "Secure shared workers are secure.");

    async_test(t => {
        var url = URL.createObjectURL(new Blob(['self.onconnect = e => { e.ports[0].postMessage({ "isSecureContext": self.isSecureContext }); };']));
        var w = new SharedWorker(url);
        w.port.onmessage = t.step_func_done(e => {
            assert_true(e.data.isSecureContext);
        });
    }, "Secure shared workers created from 'blob:' are secure.");
</script>
